Он действовал в целях самообороны, когда на него напали.
Definitions
To take action to protect oneself from imminent harm or danger, typically in response to an attack or threat, where the response is considered reasonable and necessary to prevent injury.